#include <bits/stdc++.h>
using namespace std;
int n,m,l,v,d,u,a,h[100009],ans=0,k,v1;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>k;
    for(int j=0;j<k;j++){
        cin>>n>>m>>l>>v;
        v1=v;
        ans=0;
        for(int i=0;i<n;i++){
            cin>>d>>u>>a;
            if(u>v){
                ans++;
            }
        }
        for(int i=0;i<m;i++){
            cin>>h[i];
        }
        cout<<ans<<" "<<m-1<<endl;
    }
    return 0;
}
